package com.jredu.controller.server;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jredu.entity.Role;

@Controller
@RequestMapping("/r")
public class RoleController {
	@RequestMapping("/role/toquerypage")
	public String toQueryPage(){
		return "role_query";
	}
	
	@RequestMapping(
			value={"/role/toaddpage","/role/add"},
			method=RequestMethod.POST)
	public String toAddPage(){
		return "role_add";
	}
	
	@RequestMapping(
			value="/role/delrole",
			params={"roleId!=0","roleId"})
	public String delRoleById(){
		return "role_add";
	}
	
	@RequestMapping("/role/findRoles")
	@ResponseBody
	public List<Role> findRoles(){
		List<Role> list = new ArrayList<Role>();
		Role r = new Role("管理员", "管理员");
		list.add(r);
		r = new Role("普通用户", "普通用户");
		list.add(r);
		return list;
	}
	
	@RequestMapping("/role/addRole")
	@ResponseBody
	public Role addRole( Role role){
	
		role.setId(1);
		return role;
	}
	@RequestMapping(value="/role/test",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String test() throws IOException{
		//out.write("乱码");
		return "乱码";
	}
}
